{*******************************************************************************
* The contents of this file are used with permission, subject to the Mozilla   *
* Public License Version 1.1 (the "License"); you may not use this file except *
* in compliance with the License. You may obtain a copy of the License at      *
* http://www.mozilla.org/MPL/                                                  *
*                                                                              *
* Software distributed under the License is distributed on an "AS IS" basis,   *
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for *
* the specific language governing rights and limitations under the License.    *
*                                                                              *
* The Original Code is distributed as part of the "mediate" product and is     *
* Copyright (C) @home media limited. All Rights Reserved.                      *
*                                                                              *
* Email: support@athomemedia.co.uk                                             *
* Web:   http://www.athomemedia.co.uk                                          *
*******************************************************************************}

unit DesignerReport;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, PngImageList;

type
  TfrmDesignerReport = class(TForm)
    pbHeader: TPaintBox;
    lbCaption: TLabel;
    lbAction: TLabel;
    btOkay: TButton;
    mmReport: TMemo;
    Bevel1: TBevel;
    procedure pbHeaderPaint(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure btOkayClick(Sender: TObject);
  private
    { Private declarations }
    FTextMsg: String;
    FHelpMsg: String;
    FReport: TStrings;
    FHeaderImages: TPngImageList;
    procedure ConfigureForm;
    procedure LoadImages;
  public
    { Public declarations }
    class procedure ShowReport(const Caption, TextMsg, HelpMsg: String; Report: TStrings);
    property TextMsg: String read FTextMsg write FTextMsg;
    property HelpMsg: String read FHelpMsg write FHelpMsg;
    property Report: TStrings read FReport write FReport;
  end;

implementation

{$R *.dfm}

var
  FormInstance: TfrmDesignerReport;

//-----------------------------------------------------------------------------
//----------------------------- Class Functions -------------------------------
//-----------------------------------------------------------------------------

class procedure TfrmDesignerReport.ShowReport(const Caption, TextMsg, HelpMsg: String; Report: TStrings);
begin
  // Create a singleton form instance
  if not Assigned(FormInstance) then
  begin
    FormInstance := TfrmDesignerReport.Create(Application.MainForm);
    FormInstance.PopupParent := Application.MainForm;
  end;

  FormInstance.Caption := Caption;
  FormInstance.TextMsg := TextMsg;
  FormInstance.HelpMsg := HelpMsg;
  FormInstance.Report := Report;

  FormInstance.ShowModal;
end;

//-----------------------------------------------------------------------------
//----------------------------- Form Events -----------------------------------
//-----------------------------------------------------------------------------

procedure TfrmDesignerReport.FormCreate(Sender: TObject);
begin
  // Create and populate PNG image list
  FHeaderImages := TPngImageList.Create(Self);
  LoadImages;
end;

procedure TfrmDesignerReport.FormShow(Sender: TObject);
begin
  ConfigureForm;
end;

//-----------------------------------------------------------------------------
//----------------------------- Control Events --------------------------------
//-----------------------------------------------------------------------------

procedure TfrmDesignerReport.pbHeaderPaint(Sender: TObject);
begin
  with pbHeader do
  begin
    // Draw background
    Canvas.Brush.Color := clWhite;
    Canvas.FillRect(GetClientRect);
    // Draw appropriate header image
    FHeaderImages.Draw(Canvas, ClientWidth - FHeaderImages.Width, 0, 0);
  end;
end;

procedure TfrmDesignerReport.btOkayClick(Sender: TObject);
begin
  ModalResult := mrOK;
end;

//-----------------------------------------------------------------------------
//-------------------------- User Interface Update ----------------------------
//-----------------------------------------------------------------------------

procedure TfrmDesignerReport.ConfigureForm;
begin
  lbCaption.Caption := FTextMsg;
  lbAction.Caption := FHelpMsg;
  mmReport.Lines.Assign(FReport);
end;

procedure TfrmDesignerReport.LoadImages;
begin
  with FHeaderImages do
  begin
    Clear;
    Width := 150; Height := 57;

    AddResourcePng('HD_IMG_GENERIC'); //0
  end;
end;

end.
